/*
   Copyright 2011 Jason Drake (jadrake75@gmail.com)
 
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.javad.util;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateHelper {

	private static final long TIME_PER_DAY = 86400000;
	
	/**
	 * Determine the delta in time since midnight from the date specified.
	 * 
	 * @param d	The date to get the difference from.
	 * @return
	 */
	public static long getTimeSinceMidnight(Date d) {
		Calendar calendar = GregorianCalendar.getInstance();
		calendar.setTime(d); 
		calendar.get(Calendar.HOUR_OF_DAY);
		calendar.get(Calendar.SECOND);
		calendar.get(Calendar.MONTH);  
		long diff = (calendar.get(Calendar.HOUR_OF_DAY)*3600) +(calendar.get(Calendar.MONTH)*60)+(calendar.get(Calendar.SECOND)) * 1000;
		return diff;
	}
	
	/**
	 * Determine whether the two date long values occur on different days.
	 * 
	 * @param newDate
	 * @param original
	 * @return
	 */
	public static boolean differentDays(long newDate, long original) {
		return newDate > original + TIME_PER_DAY;
	}
}
